home *** CD-ROM | disk | FTP | other *** search
/ Computer Music 2004 January / Computer Music Magazine 68 2004.iso / pc / Software / MAC Software / Full Software / Free Effects Mac / Smartelectronix - Bram / Madshifta OS9x OSX / source / madshifta / madshifta.hpp < prev   
Encoding:
C/C++ Source or Header  |  2002-08-23  |  5.7 KB  |  185 lines

  1. #ifndef __madshifta
  2. #define __madshifta
  3.  
  4. #include <math.h>
  5.  
  6. #include "audioeffectx.h"
  7.  
  8.  
  9. // some very important VST variables are defined here:
  10.  #define p4 1e-24f // the threshold for denormalisation on Pentium 4 CPUs
  11.  #define kID 'TBMS' // unique plugin identifier, has to be different for every plugin
  12.  #define kChannelID "MadS" // string displayed in the VSTi channel mixer
  13.  #define kEffectName "MadShifta" // effect name
  14.  #define kProduct "MadShifta" // product name
  15.  #define kVendor "Tobybear" // vendor name
  16.  #define kVersion 1030    // version number:  major/minor/bugfix/more
  17.  const bool kIsSynth = false; //false=audio effect, true=synth
  18.  const long kNumInputs = 2; // number of inputs
  19.  const long kNumOutputs = 2; // number of outputs
  20.  const bool kCanMono = true; // can be fed with mono signals?
  21.  const bool kCanReplacing = true; //processreplacing() is called instead of process()
  22.  
  23.  // then we have the settings for the MIDI CC controllers, i.e.
  24.  // what dial is controlled by what CC:
  25.  const long kCC_Tune = 68;
  26.  const long kCC_Fine = 69;
  27.  const long kCC_Length = 70;
  28.  const long kCC_Reso = 71;
  29.  const long kCC_Feedback = 72;
  30.  const long kCC_DryWet = 73;
  31.  const long kCC_Cutoff = 74;
  32.  const long kCC_OutVol = 75;
  33.  
  34.  
  35.  const long kNumPrograms = 16; // 16 programs per fxb bank
  36.  const long kNumChannels = 2;    // 2 channel mode, might be expanded in future
  37.  
  38.  const long kFadeSize = 100001;
  39.  const long kBufferSize = 65537;
  40.  
  41.  
  42.  const long kNumMidi = 128;
  43.  const long kTuneMin = -24;
  44.  const long kTuneMax = 24;
  45.  
  46.  
  47.  const char * const midiNoteNames[128] = {
  48.   "C-1","C#-1","D-1","D#-1","E-1","F-1","F#-1","G-1","G#-1","A-1","A#-1","B-1",
  49.   "C 0","C#0","D 0","D#0","E 0","F 0","F#0","G 0","G#0","A 0","A#0","B 0",
  50.   "C 1","C#1","D 1","D#1","E 1","F 1","F#1","G 1","G#1","A 1","A#1","B 1",
  51.   "C 2","C#2","D 2","D#2","E 2","F 2","F#2","G 2","G#2","A 2","A#2","B 2",
  52.   "C 3","C#3","D 3","D#3","E 3","F 3","F#3","G 3","G#3","A 3","A#3","B 3",
  53.   "C 4","C#4","D 4","D#4","E 4","F 4","F#4","G 4","G#4","A 4","A#4","B 4",
  54.   "C 5","C#5","D 5","D#5","E 5","F 5","F#5","G 5","G#5","A 5","A#5","B 5",
  55.   "C 6","C#6","D 6","D#6","E 6","F 6","F#6","G 6","G#6","A 6","A#6","B 6",
  56.   "C 7","C#7","D 7","D#7","E 7","F 7","F#7","G 7","G#7","A 7","A#7","B 7",
  57.   "C 8","C#8","D 8","D#8","E 8","F 8","F#8","G 8","G#8","A 8","A#8","B 8",
  58.   "C 9","C#9","D 9","D#9","E 9","F 9","F#9","G 9"
  59.  };
  60.  
  61.  
  62.  
  63.  // and finally the set of constants defining the effect's parameter set:
  64. enum
  65. {
  66.  kTune,
  67.  kFine,
  68.  kDelayLen,
  69.  kDelayFB,
  70.  kCutoff,
  71.  kResonance,
  72.  kFType,
  73.  kOutVol,
  74.  kDryWet,
  75.  kRoot,
  76.  kMMode,
  77.  kpar12, // reserved for future use
  78.  kpar13,
  79.  kpar14,
  80.  kpar15,
  81.  kpar16,
  82.  
  83.  kNumParams   // 0-15, can be adjusted to your wishes
  84. };
  85.  
  86.  
  87. // these are some macros for converting some of the parameters' 
  88. // values from VST-style 0.0 to 1.0 value to their actual values
  89. #define tuneScaled(value)   ( (int) round( ((value)*(float)(kTuneMax-kTuneMin)) + (float)kTuneMin ) )
  90. #define fineTuneScaled(value)   ( ((value)*200.0f) - 100.0f )
  91. #define rootKeyScaled(value)   ( (int)round( ((value)*(float)(kNumMidi-(kTuneMax-kTuneMin))) ) - kTuneMin )
  92.  
  93.  
  94. class APluginProgram
  95. {
  96.  friend class APlugin;
  97.  private:
  98.   // the parameter set for one program:
  99.   float fDryWet, fTune, fDelayLen, fDelayFB, fFine, fRoot, fMMode, 
  100.   fCutoff, fResonance, fFType, fOutVol;
  101.   // program name:
  102.   char name[51];
  103.  
  104.  public:
  105.   APluginProgram();
  106. };
  107.  
  108.  
  109.  
  110. class APlugin : public AudioEffectX
  111. {
  112.  private:
  113.   // the current parameter set in memory:
  114.   float fDryWet, fTune, fDelayLen, fDelayFB, fFine, fRoot, fMMode, 
  115.   fCutoff, fResonance, fFType, fOutVol;
  116.  
  117.   // the buffers:
  118.   float *fade;
  119.   float **delay, //the delay buffer
  120.   **buffer; // the shift buffer
  121.  
  122.   // some variables for the algorithm:
  123.   float last[kNumChannels], old1[kNumChannels], old2[kNumChannels]; // filter variables
  124.   int semitones; // semitone shift (can be negative)
  125.   float oldtune, // last valid MIDI tuning
  126.   cut, reso; // current cutoff and resonance values
  127.   unsigned long p1, p2, // output pointers
  128.   delay_in, delay_out, // delay buffer pointers
  129.   inp, // input pointer for the shift-buffer
  130.   dp, // pointer increment
  131.   nBuffer, nSize, // determine size of fade buffer
  132.   displace, nDelay;
  133.  
  134.   int notecount; // number of notes currently held down
  135.  
  136.  public:
  137.   APlugin(audioMasterCallback audioMaster);
  138.   ~APlugin();
  139.   APluginProgram *programs;
  140.   float vu;
  141.   void DoProcess(float *i);
  142.   virtual void process(float **inputs, float **outputs, long sampleframes);
  143.   virtual void processReplacing(float **inputs, float **outputs, long sampleframes);
  144.   virtual void setProgram(long aProgram);
  145.   virtual long canDo(char *text);
  146.   virtual void setProgramName(char *name);
  147.   virtual void getProgramName(char *name);
  148.   virtual void setParameter(long index, float value);
  149.   virtual float getParameter(long index);
  150.   virtual float getVu();
  151.   float DoFilter(float i, float cutoff, float res, unsigned char ch);
  152.   virtual long processEvents(VstEvents *ev);
  153.   virtual void resume();
  154.   virtual void suspend();
  155.   virtual void getParameterLabel(long index, char *text);
  156.   virtual void getParameterDisplay(long index, char *text);
  157.   virtual void getParameterName(long index, char *text);
  158.   virtual bool getOutputProperties(long index, VstPinProperties *properties);
  159.   virtual bool getProgramNameIndexed(long category, long index, char *text);
  160.   virtual bool getEffectName(char *name);
  161.   virtual bool getVendorString(char *text);
  162.   virtual bool getProductString(char *text);
  163.   virtual long getVendorVersion();
  164. };
  165.  
  166.  
  167.  
  168. // this function gives you the smallest power of 2
  169. // that is larger than/equal to "number"
  170. inline unsigned int n_larger(unsigned int number)
  171. {
  172.  unsigned int numb = 1;
  173.  while (numb < number) numb = numb << 1;
  174.  return numb;
  175. }
  176.  
  177. // simple approximation
  178. inline double powerof2(double a)
  179. {
  180.  return exp(a * 0.69314718056);
  181. }
  182.  
  183.  
  184. #endif
  185.